package com.qianbei.user.withdrawal;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qianbei.R;

import java.util.List;

/**
 * Created by GaoQian on 2017/11/8.
 */

public class GvWdListAdapter extends BaseAdapter {
    private Context mContext;
    private List<WithDrawalBean.DataBean.QuotaBean> quotaBeanList;

    public GvWdListAdapter(Context mContext, List<WithDrawalBean.DataBean.QuotaBean> quotaBeanList) {
        this.mContext = mContext;
        this.quotaBeanList = quotaBeanList;
    }

    @Override
    public int getCount() {
        return quotaBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.kh_item_withdrawal, null);
            viewHolder = new ViewHolder();
            viewHolder.mTvWdNum = (TextView) convertView.findViewById(R.id.tv_wd_num);
            viewHolder.mTvWdMoney = (TextView) convertView.findViewById(R.id.tv_wd_money);
            viewHolder.mLlWdBg = (LinearLayout) convertView.findViewById(R.id.ll_wd_bg);


            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        int num = quotaBeanList.get(position).getNum();
        int money = quotaBeanList.get(position).getMoney();
        viewHolder.mTvWdNum.setText("库存" + num + "个");
        viewHolder.mTvWdMoney.setText(money + "元");
        if (!quotaBeanList.get(position).isSelected()) {
            viewHolder.mLlWdBg.setBackgroundResource(R.drawable.roll_wd_white);
            viewHolder.mTvWdNum.setTextColor(Color.parseColor("#212121"));
            viewHolder.mTvWdMoney.setTextColor(Color.parseColor("#212121"));
        }
        if (num == 0) {
            viewHolder.mLlWdBg.setBackgroundResource(R.drawable.roll_wd_gray);
            viewHolder.mTvWdNum.setTextColor(Color.WHITE);
            viewHolder.mTvWdMoney.setTextColor(Color.WHITE);
        }

        return convertView;
    }


    class ViewHolder {
        TextView mTvWdNum;
        TextView mTvWdMoney;
        LinearLayout mLlWdBg;

    }
}
